/**
 * Created by felix on 2017/2/25.
 */
import React from 'react';
import _ from 'lodash';
import TBody from './tbody';
import THead from './thead';
import styles from './index.less';

function Table({ data, cols, extra, openIndex, onPress}) {
    const items = (data, cols, extra) => _.map(data, (d, i) => (
        <TBody
            key={`tbody_${i}`}
            data={d}
            cols={cols}
            index={i}
            extra={extra}
            isOpen={openIndex === i}
            onPress={onPress}
        />
    ));
    return (
        <table
            className={styles.table}
            cellSpacing={0}
        >
            <THead cols={cols} />
            {items(data, cols, extra)}
        </table>
    );
}

export default Table;
